package com.von.controller;

import com.von.entity.User;
import com.von.param.PdfParam;
import com.von.param.UserParam;
import com.von.result.R;
import com.von.service.IUserService;
import com.von.util.PdfUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author xiaosai
 * @since 2021-06-17
 */
@RestController
@RequestMapping("/user")
@Validated
public class UserController {
    /**
     * @apiDefine user 用户管理
     */

    @Autowired
    private IUserService iUserService;

    /**
     * @api {post} /user/login 登录
     * @apiGroup user
     * @apiParam {String} userName 用户名[必填]
     * @apiParam {String} userPassword 用户密码[必填]
     * @apiParamExample {json} Request-Example:
     * {
     *     "userName":"admin",
     *     "userPassword":"123456",
     *     "phone":"123456"
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping ("/login")
    public R<String> login(@RequestBody @Validated(value = {UserParam.class}) UserParam param){
        return iUserService.login(param);
    }

    /**
     * @api {get} /user/logout 登出
     * @apiGroup user
     * @apiParam {String} token token[必填]
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @GetMapping("/logout")
    public R<String> logout(String token){
        return iUserService.logout(token);
    }

    /**
     * @api {post} /user/register 注册
     * @apiGroup user
     * @apiParam {String} userName 用户名
     * @apiParam {String} userPassword 用户密码
     * @apiParam {String} phone 手机号
     * @apiParam {Integer} sex 性别
     * @apiParamExample {json} Request-Example:
     * {
     *     "userName":"admin",
     *     "userPassword":"123456",
     *     "phone":"123456",
     *     "sex":0
     * }
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code":0，
     *     “msg”:"执行成功"，
     *     “data”:null
     * }
     */
    @PostMapping("/register")
    public R register(@RequestBody User user){
        return iUserService.register(user);
    }
}
